import { createAlova } from 'alova'
import fetchAdapter from 'alova/fetch'
import { createApis, withConfigType, mountApis } from './createApis'
import vueHook from 'alova/vue'
import { beforeRequest, onSuccess, onError } from './interceptor'

export const alovaInstance = createAlova({
  baseURL: 'http://192.168.60.102:9001/api/v1/',
  statesHook: vueHook,
  requestAdapter: fetchAdapter(),
  timeout: 5000,
  responded: {
    onSuccess,
    onError,
    // onComplete: () => console.log('请求结束'),
  },
  beforeRequest,
  cacheFor: null,
})

export const $$userConfigMap = withConfigType({})

const Apis = createApis(alovaInstance, $$userConfigMap)

mountApis(Apis)

export default Apis
